package com.ruoyi.fetv.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.aspect.annotation.AutoDict;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.fetv.controller.vo.audit.AuditReq;
import com.ruoyi.fetv.controller.vo.audit.RespVO;
import com.ruoyi.fetv.controller.vo.audit.SearchReq;
import com.ruoyi.fetv.controller.vo.audit.UpdateStatus;
import com.ruoyi.fetv.domain.FetvInformation;
import com.ruoyi.fetv.service.IFetvAuditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 审核Controller
 *
 * @author Jack
 * @date 2023-03-07
 */
@Api(value = "/fetv/audit", tags = {"审核管理"})
@RestController
@RequestMapping("/fetv/audit")
@Validated
@AutoDict
class FetvAuditController extends BaseController {
    @Autowired
    private IFetvAuditService fetvAuditService;

    /**
     * 查询审核列表
     */
    @ApiImplicitParam(paramType = "query", dataType = "FetvAuditSearch", name = "fetvAudit", value = "", required = true)
    @ApiOperation(value = "查询审核列表", notes = "查询审核列表", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('fetv:audit:list')")
    @ApiResponse(code = 200, message = "", response = TableDataInfo.class)
    @GetMapping("/list")
    public TableDataInfo<List<RespVO>> list(SearchReq fetvAudit) {
        startPage();
        List<RespVO> list = fetvAuditService.selectFetvAuditList(fetvAudit);
        return getDataTable(list);
    }

    /**
     * 获取审核详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "获取审核详细信息", notes = "获取审核详细信息", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('fetv:audit:query')")
    @ApiResponse(code = 200, message = "", response = FetvInformation.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        FetvInformation data = fetvAuditService.selectFetvAuditById(id);
        if (data == null) {
            throw new ServiceException("不存在的ID");
        }
        return success(data);
    }

    /**
     * 审核
     */

    @ApiOperation(value = "审核", notes = "修改审核", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('fetv:audit:edit')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @PutMapping
    public AjaxResult audit(@ApiParam(name = "fetvAudit", value = "审核信息", required = true) @RequestBody @Valid AuditReq fetvAudit) {
        return toAjax(fetvAuditService.audit(fetvAudit));
    }

    /**
     * 设置状态
     */

    @ApiOperation(value = "修改状态", notes = "修改状态", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('fetv:audit:edit')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @PutMapping("/status")
    public AjaxResult edit(@ApiParam(name = "fetvAudit", value = "审核信息", required = true) @RequestBody @Valid UpdateStatus fetvAudit) {
        return toAjax(fetvAuditService.updateStatus(fetvAudit));
    }


    /**
     * 删除审核
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "Long[]", name = "ids", value = "", required = true)
    })
    @ApiOperation(value = "删除审核", notes = "删除审核", httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('fetv:audit:remove')")
    @Log(title = "审核", businessType = BusinessType.DELETE)
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fetvAuditService.deleteFetvAuditByIds(ids));
    }
}
